<?php
/**
 * @author Radovan Dvorsky
 * @version 20100403
 */
require_once ('Zend/Form.php');

class Form_Commission_AddProfessor extends My_Form_AjaxForm {
	
	protected $_professors; 
	
	public function init(){
			
		$cache = Zend_Registry::get('cache');
		$cacheName = My_Support::getCacheName('ProfessorController','fetchAll');
		
		if(!($this->_professors = $cache->load($cacheName))){
			$professorMapper = new Db_Mapper_Professor();
			$this->_professors = $professorMapper->fetchAll();
			$cache->save($this->_professors,$cacheName,array('ProfessorController'));
		}
	}
	
	public function __construct($url,$update,$format = 'html',$options = null) {
		parent::__construct ($options);
		
		$this->setMethod('post');
		
		$this->setJqueryParams(array(
				'url' => $url,
				'update' => $update,
				'format' => $format,
				'append' => true	
			)
		);
		
		$professorSelect = new Zend_Form_Element_Select('pid');		
		$professorSelect->setDecorators(array('ViewHelper'));
		foreach($this->_professors as $professor){
			$professorSelect->addMultiOption(
				$professor->getPid(),
				$professor->getFirstName() . ' ' . $professor->getLastname()
			);
		}
		
		$commissionId = new Zend_Form_Element_Hidden('cid');		
		$commissionId->setDecorators(array('ViewHelper'));
					
		
		$submit = new Zend_Form_Element_Button('submitProfessor');		
		$submit->setDecorators(array('ViewHelper'))
		->setLabel('Pridať');
		
		$this->addAjaxableElements(array($professorSelect,$commissionId));
		$this->setSender($submit,'onClick');
				
		$this->addElements(array($professorSelect,$submit,$commissionId));		
	}
}